#include<bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
typedef long long ll;
const int N = 500050;
const int M = 500050;
struct QueueNode{
    ll to,w;
    QueueNode(){}
    QueueNode(ll x,ll y) : to(x) , w(y) {}
    bool operator < (const QueueNode &x) const {
        return w > x.w;
    }
};
vector<QueueNode> G[M];
priority_queue<QueueNode> q;
ll n,m,s = 1;
ll dis[N],ans = 0;
bool vis[N] = {0};
int main(){
    scanf("%lld%lld",&n,&m);
    ll u,v,w;
    for(ll i = 1;i <= m;i++){
        scanf("%lld%lld%lld",&u,&v,&w);
        G[u].push_back(QueueNode(v,w));
        G[v].push_back(QueueNode(u,w));
    }
    for(ll i = 1;i <= n;i++)dis[i] = INF;
    dis[s] = 0;
    q.push(QueueNode(s,0));
    while(!q.empty()){
        QueueNode p = q.top(); q.pop();
        if(vis[p.to])continue;
        vis[p.to] = true;
        ans += p.w;
        // printf("%lld\n",p.w);
        for(ll i = 0;i < G[p.to].size();i++){
            QueueNode u = G[p.to][i];
            if(!vis[u.to] && dis[u.to] > u.w){
                dis[u.to] = u.w;
                q.push(QueueNode(u.to,u.w));
            }
        }
    }
    for(ll i = 1;i <= n;i++){
        if(dis[i] == INF){
            printf("orz\n");
            return 0;
        }
        // ans += dis[i];
    }
    printf("%lld\n",ans);
    return 0;
}